package com.pennywise.config;

import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * 数据库初始化器
 * 负责在数据库不存在时创建必要的数据库表和初始数据
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class DatabaseInitializer {
    
    private static final String BASE_DIR = System.getProperty("user.dir") + "/data";
    
    @PostConstruct
    public void initialize() {
        String dbPath = BASE_DIR + "/db/pennywise.db";
        File dbFile = new File(dbPath);
        
        if (!dbFile.exists()) {
            log.info("数据库文件不存在，将创建新数据库: {}", dbPath);
            dbFile.getParentFile().mkdirs();
        } else {
            log.info("数据库文件已存在: {}", dbPath);
        }
    }
} 